import re

html = """
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>正则1</title></title>
    <title>正则2</title>
</head>
<body>
<h1>正则表达式</h1>
<h2>hello</h2>
<h2>Hello</h2>
<ul>
    <li><a href="https://www.baidu.com/new/1">链接1</a></li>
    <li><a href="https://www.baidu.com/new/2">链接2</a></li>
    <li><a href="https://www.baidu.com/new/3">链接3</a></li>
    <li><a href="https://www.baidu.com/new/4">链接4</a></li>
    <li><a href="https://www.baidu.com/new/5">链接5</a></li>
</ul>

</body>
</html>

"""

# r = re.search(r'<title>正则</title>',html) #判断是否存在固定的标题字符串并获取匹配对象,返回match对象
# r = re.search(r'<title>(.*?)</title>',html).group(1) # 提取任意标题标签内的文本内容
# r1 = re.findall(r'<title>(.*?)</title>', html) # 提取所有标题标签内的文本内容
# print(r)
# print(r1)

# r2 = re.search(r'<title>(.*)</title>',html).group(1)
# print(r2)

# r3 = re.search(r'<li><a href="(.*?)">(.*?)</a></li>', html)
# print(r3.group(1),r3.group(2))
#
# r4 = re.findall(r'<li><a href="(.*?)">(.*?)</a></li>', html)
# print(r4)
# for i in r4:
#     print(f"链接：{i[0]}, 名称：{i[1]}")

# # re.I 匹配时不区分字母的大小写
# r5 = re.findall(r'<h2>hello</h2>',html,re.I)
# print(r5)
#
# # re.M 使 ^ 和 $ 匹配每行的开头和结尾
# text = "one hello\ntwo hello\nthree hello"
# r6 = re.findall(r'^hello', text, re.M)
# r7 = re.findall(r'^two', text,re.M)
# r8 = re.findall(r'hello$', text, re.M)
# print(r6,r7,r8)
#
# # re.S 使 . 匹配任意字符 re.S 让 . 也能匹配 \n
# text = "one hello\ntwo hello\nthree hello"
# r9 = re.findall(r'.*', text, re.S)
# print(r9)


eg = "hello @ 1234 ? 秦尘"

# \w：匹配字母、数字、下划线
print(re.findall(r'\w',eg))
# \W：匹配非字母、数字、下划线
print(re.findall(r'\W', eg))
# \d：匹配数字
print(re.findall(r'\d', eg))
# \D：匹配非数字
print(re.findall(r'\D', eg))
# \s：匹配空白字符
print(re.findall(r'\s', eg))
# \S：匹配非空白字符
print(re.findall(r'\S', eg))
# \b：匹配单词边界
print(re.findall(r'\bhello\b', eg))
# \B：匹配非单词边界
print(re.findall(r'\Bhello\B', eg))




